/**
 * merge level=50
 * 
 * 金额单位的选择控件,选择过后会将所有的grid刷新一次
 */

Ext.define('Jfok.view.widget.MonetarySelect', {
			extend : 'Jfok.lib.ButtonTransparent',
			alias : 'widget.monetaryselect',
			unittext : '单位：',
			initComponent : function() {
				this.monetarys = [{
							text : '元',
							div : 1
						}, {
							text : '千元',
							div : 1000
						}, {
							text : '万元',
							div : 10000
						}, {
							text : '百万元',
							div : 1000 * 1000
						}, {
							text : '亿元',
							div : 10000 * 10000
						}];
				this.changeMonetary(Cookies.get('monetary', '万元'));
				this.menu = [];
				for (var i in this.monetarys) {
					this.menu.push(Ext.apply({
								xtype : 'monetaryitem',
								checked : this.monetarys[i].text == Jfok.system.monetary
							}, this.monetarys[i]))
				}
				this.callParent(arguments);
			},

			changeMonetary : function(text) {
				Jfok.system.monetary = text;
				this.setText(this.unittext + text);
				for (var i in this.monetarys) {
					if (this.monetarys[i].text == Jfok.system.monetary)
						Jfok.system.monetaryUnit = this.monetarys[i].div;
				}
				Jfok.system.monetaryUnitText = Jfok.system.monetary.replace('元', '');
			}

		});

Ext.define('Jfok.view.widget.MonetaryItem', {
	extend : 'Ext.menu.CheckItem',
	group : 'monetary_',
	alias : 'widget.monetaryitem',
	handler : function(menuitem) {
		menuitem.up('toolbar').down('monetaryselect').changeMonetary(menuitem.text);
		Cookies.set('monetary', menuitem.text);
		Ext.each(menuitem.up('viewport').query('modulegrid'), function(item) {
					item.getView().refresh();
					item.updateRecordDetail(item.getSelectionModel().getSelection());
				});
		Ext.each(menuitem.up('viewport').query('resultlistgrid'), function(item) {
					item.getView().refresh();
				});
	}
});
